import { queryUserListAPI } from '@/api/user'
import { IPaginationFormWithCondition } from '@/types/http'
import { reactive, ref } from 'vue'

export default function () {
  const tableColumns = [
    {
      label: '邮箱',
      prop: 'email'
    },
    {
      label: '用户名',
      prop: 'username'
    },
    {
      label: '昵称',
      prop: 'nickName'
    },
    {
      label: '状态',
      prop: 'status'
    },
    {
      label: '电话',
      prop: 'telephone'
    },
    {
      label: '创建时间',
      prop: 'createdAt',
      isTime: true
    },
    {
      label: '更新时间',
      prop: 'updatedAt',
      isTime: true
    }
  ]

  const tableData = ref<any>([])
  const page = reactive<IPaginationFormWithCondition>({
    pageNum: 1,
    pageSize: 20,
    total: 0
  })
  const queryForm = reactive({
    username: ''
  })
  const options = {
    showOrder: false
  }

  const queryUserList = async () => {
    try {
      const res = await queryUserListAPI({ ...page, ...queryForm })
      tableData.value = res.data.list
      page.total = res.data.total
    } catch (e) {
      console.log(e)
    }
  }
  return {
    tableColumns,
    tableData,
    options,
    page,
    queryForm,
    queryUserList
  }
}
